package data
{
	import flash.geom.Point;
	
	public class cd_utils {
		public static function resetData(infoList: Array, groupSet: int = -1): void {
			
			function createElement(source: Object, index: int, num: int): Object {
				var setObj: Object = new Object();
				for (var i: String in source) {
					if (i != 'id') {
						if (source[i] is Array)
							setObj[i] = source[i][num];
						else setObj[i] = source[i];
					} else setObj.id = index;
				}
				return setObj;
			}
			
			var i: int;
			
			for (i = 0; i<infoList.length; i++) {
				var obj: Object = infoList[i];
				if (obj.id is Array) {
					infoList.splice(i, 1);
					i--;
					var num: int = 0;
					for (var n: int = obj.id[0]; n <= obj.id[1]; n++) {
						infoList.push(createElement(obj, n, num));
						num++;
					} 
				}
			}
			
			infoList.sortOn('id', Array.NUMERIC | Array.DESCENDING);
			for (i = 0; i<infoList.length; i++) {
				var item: Object = infoList[i];
				if (groupSet > -1) {
					item.group = groupSet;
/*					var tmpl: Object = pi_data.infoFromID(infoList[i].id);
					if (tmpl) infoList[i] = uif_util.union(tmpl, data);*/
				}
			}
		}
		
		public static function fromID(list: Array, id: int): Object {
			var filterList: Array = list.filter(function(item: Object, index: int, arr: Array): Boolean {
				return item.id == id;
			});
			return (filterList.length>0)?filterList[0]:null;
		}
		
		
		public static function getEars(item: Object): Array {
			return [
				new Point(item.ears[0], item.ears[1]),
				new Point(item.ears[2], item.ears[3])
			]
		} 		
	}
}